-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($compile): avoid calling $onChanges()
twice for NaN
initial values
#15098
fix($compile): avoid calling $onChanges()
twice for NaN
initial values
#15098
Conversation
if (isFunction(destination.$onChanges) && currentValue !== previousValue) { | ||
if (isFunction(destination.$onChanges) && currentValue !== previousValue && | ||
// eslint-disable-next-line no-self-compare | ||
(currentValue === currentValue || previousValue === previousValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this will not trigger a call to $onChanges
if we go from a real number to NaN
, no?
Sorry I forgot about the currentValue !== previousValue
check before it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think a test of that situation would be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Landed but forgot to add this extra test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add the extra test. It is good excuse to fix an indentation issue 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: c0cbe54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wouldn't believe how much time I spent fixing up the indentation in my conflict editor :-)
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
What is the current behavior? (You can also link to an open issue here)
When the initial value of a binding is
NaN
,$onChanges()
will be called twice (because we fail to detect thatNaN
equalsNaN
. For all other values,$onChanges()
is called once.What is the new behavior (if this is a feature change)?
$onChanges()
is always called once, even if the initial value of a binding isNaN
.Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Docs have been added / updated (for bug fixes / features)Other information:
Discussed in #15095.